<template>
  <div class="case-study">
    <div class="page-header">
      <h1>案例学习</h1>
      <p>通过真实案例学习识别和防范各类诈骗</p>
    </div>

    <!-- 案例分类 -->
    <div class="case-categories">
      <button 
        v-for="category in categories" 
        :key="category.id"
        class="category-btn"
        :class="{active: activeCategory === category.id}"
        @click="switchCategory(category.id)"
      >
        <i :class="category.icon"></i>
        {{ category.name }}
        <span class="count">({{ category.count }})</span>
      </button>
    </div>

    <!-- 案例列表 -->
    <div class="case-list">
      <div class="case-card" v-for="case_ in filteredCases" :key="case_.id">
        <div class="case-header">
          <div class="case-type">{{ case_.type }}</div>
          <div class="case-difficulty" :class="case_.difficulty">{{ case_.difficultyText }}</div>
        </div>
        
        <div class="case-content">
          <h3>{{ case_.title }}</h3>
          <p class="case-summary">{{ case_.summary }}</p>
          
          <div class="case-tags">
            <span class="tag" v-for="tag in case_.tags" :key="tag">{{ tag }}</span>
          </div>
          
          <div class="case-meta">
            <div class="meta-item">
              <i class="fas fa-calendar"></i>
              <span>{{ formatDate(case_.date) }}</span>
            </div>
            <div class="meta-item">
              <i class="fas fa-eye"></i>
              <span>{{ case_.views }} 浏览</span>
            </div>
            <div class="meta-item">
              <i class="fas fa-clock"></i>
              <span>{{ case_.readTime }} 阅读</span>
            </div>
          </div>
        </div>
        
        <div class="case-actions">
          <button class="btn btn-primary" @click="viewCase(case_)">
            查看案例
          </button>
          <button class="btn btn-secondary" @click="addToFavorites(case_)">
            <i class="fas fa-heart"></i>
            收藏
          </button>
        </div>
      </div>
    </div>

    <!-- 热门案例 -->
    <div class="popular-cases">
      <h2>热门案例</h2>
      <div class="popular-grid">
        <div class="popular-card" v-for="case_ in popularCases" :key="case_.id">
          <div class="popular-rank">{{ case_.rank }}</div>
          <div class="popular-content">
            <h3>{{ case_.title }}</h3>
            <p>{{ case_.summary }}</p>
            <div class="popular-meta">
              <span class="views">{{ case_.views }} 浏览</span>
              <span class="type">{{ case_.type }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 学习进度 -->
    <div class="learning-progress">
      <h2>学习进度</h2>
      <div class="progress-stats">
        <div class="stat-item">
          <div class="stat-number">{{ studiedCases }}</div>
          <div class="stat-label">已学习案例</div>
        </div>
        <div class="stat-item">
          <div class="stat-number">{{ totalTime }}</div>
          <div class="stat-label">总学习时长</div>
        </div>
        <div class="stat-item">
          <div class="stat-number">{{ correctRate }}%</div>
          <div class="stat-label">答题正确率</div>
        </div>
      </div>
      
      <div class="progress-by-category">
        <div class="progress-item" v-for="category in categories" :key="category.id">
          <div class="progress-header">
            <span>{{ category.name }}</span>
            <span>{{ category.studied }}/{{ category.count }}</span>
          </div>
          <div class="progress-bar">
            <div class="progress-fill" :style="{width: (category.studied / category.count * 100) + '%'}"></div>
          </div>
        </div>
      </div>
    </div>

    <!-- 最新讨论 -->
    <div class="recent-discussions">
      <h2>最新讨论</h2>
      <div class="discussion-list">
        <div class="discussion-item" v-for="discussion in discussions" :key="discussion.id">
          <div class="discussion-avatar">
            <img :src="discussion.avatar" :alt="discussion.username">
          </div>
          <div class="discussion-content">
            <div class="discussion-header">
              <span class="username">{{ discussion.username }}</span>
              <span class="case-title">在案例《{{ discussion.caseTitle }}》中</span>
              <span class="time">{{ formatTime(discussion.time) }}</span>
            </div>
            <div class="discussion-text">{{ discussion.content }}</div>
            <div class="discussion-actions">
              <button class="action-btn">
                <i class="fas fa-thumbs-up"></i>
                {{ discussion.likes }}
              </button>
              <button class="action-btn">
                <i class="fas fa-comment"></i>
                回复
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'

// 响应式数据
const activeCategory = ref('all')
const studiedCases = ref(25)
const totalTime = ref('12小时')
const correctRate = ref(85)

// 案例分类
const categories = ref([
  {
    id: 'all',
    name: '全部',
    icon: 'fas fa-th-large',
    count: 48,
    studied: 25
  },
  {
    id: 'telecom',
    name: '电信诈骗',
    icon: 'fas fa-phone',
    count: 15,
    studied: 10
  },
  {
    id: 'network',
    name: '网络诈骗',
    icon: 'fas fa-globe',
    count: 12,
    studied: 8
  },
  {
    id: 'financial',
    name: '金融诈骗',
    icon: 'fas fa-credit-card',
    count: 10,
    studied: 4
  },
  {
    id: 'identity',
    name: '身份冒充',
    icon: 'fas fa-user-secret',
    count: 8,
    studied: 2
  },
  {
    id: 'romance',
    name: '情感诈骗',
    icon: 'fas fa-heart-broken',
    count: 6,
    studied: 1
  }
])

// 案例数据
const cases = ref([
  {
    id: 1,
    title: '冒充公检法诈骗案例分析',
    summary: '犯罪分子冒充公检法人员，以涉嫌洗钱为由要求转账',
    type: '电信诈骗',
    category: 'telecom',
    difficulty: 'beginner',
    difficultyText: '入门',
    tags: ['电话诈骗', '身份冒充', '恐吓威胁'],
    date: '2024-01-20',
    views: 1234,
    readTime: '8分钟'
  },
  {
    id: 2,
    title: '网络购物退款诈骗案例',
    summary: '诈骗分子冒充客服，以退款为由骗取银行卡信息',
    type: '网络诈骗',
    category: 'network',
    difficulty: 'intermediate',
    difficultyText: '中级',
    tags: ['网购诈骗', '退款诈骗', '信息盗取'],
    date: '2024-01-19',
    views: 987,
    readTime: '10分钟'
  },
  {
    id: 3,
    title: '投资理财诈骗案例解析',
    summary: '虚假投资平台诱导用户投资，最终卷款潜逃',
    type: '金融诈骗',
    category: 'financial',
    difficulty: 'advanced',
    difficultyText: '高级',
    tags: ['投资诈骗', '虚假平台', '高额回报'],
    date: '2024-01-18',
    views: 2156,
    readTime: '15分钟'
  },
  {
    id: 4,
    title: '交友软件杀猪盘案例',
    summary: '诈骗分子通过交友软件建立恋爱关系，诱导投资',
    type: '情感诈骗',
    category: 'romance',
    difficulty: 'advanced',
    difficultyText: '高级',
    tags: ['杀猪盘', '交友诈骗', '情感操控'],
    date: '2024-01-17',
    views: 1678,
    readTime: '12分钟'
  },
  {
    id: 5,
    title: '冒充熟人借款诈骗',
    summary: '诈骗分子盗用微信头像昵称，冒充熟人借款',
    type: '身份冒充',
    category: 'identity',
    difficulty: 'beginner',
    difficultyText: '入门',
    tags: ['身份冒充', '熟人诈骗', '微信诈骗'],
    date: '2024-01-16',
    views: 834,
    readTime: '6分钟'
  }
])

// 热门案例
const popularCases = ref([
  {
    id: 1,
    rank: 1,
    title: '冒充公检法诈骗案例分析',
    summary: '犯罪分子冒充公检法人员，以涉嫌洗钱为由要求转账',
    type: '电信诈骗',
    views: 1234
  },
  {
    id: 2,
    rank: 2,
    title: '投资理财诈骗案例解析',
    summary: '虚假投资平台诱导用户投资，最终卷款潜逃',
    type: '金融诈骗',
    views: 2156
  },
  {
    id: 3,
    rank: 3,
    title: '交友软件杀猪盘案例',
    summary: '诈骗分子通过交友软件建立恋爱关系，诱导投资',
    type: '情感诈骗',
    views: 1678
  }
])

// 讨论数据
const discussions = ref([
  {
    id: 1,
    username: '张三',
    avatar: '/api/placeholder/40/40',
    caseTitle: '冒充公检法诈骗案例分析',
    content: '这个案例很典型，我之前也遇到过类似的情况，幸好及时识破了。',
    time: '2024-01-20 14:30',
    likes: 12
  },
  {
    id: 2,
    username: '李四',
    avatar: '/api/placeholder/40/40',
    caseTitle: '网络购物退款诈骗案例',
    content: '现在的诈骗手法越来越高明，大家一定要提高警惕。',
    time: '2024-01-20 13:45',
    likes: 8
  },
  {
    id: 3,
    username: '王五',
    avatar: '/api/placeholder/40/40',
    caseTitle: '投资理财诈骗案例解析',
    content: '投资一定要选择正规平台，不要贪图高收益。',
    time: '2024-01-20 12:20',
    likes: 15
  }
])

// 计算属性
const filteredCases = computed(() => {
  if (activeCategory.value === 'all') {
    return cases.value
  }
  return cases.value.filter(case_ => case_.category === activeCategory.value)
})

// 方法
const switchCategory = (categoryId) => {
  activeCategory.value = categoryId
}

const viewCase = (case_) => {
  alert(`查看案例: ${case_.title}`)
}

const addToFavorites = (case_) => {
  alert(`收藏案例: ${case_.title}`)
}

const formatDate = (dateString) => {
  return new Date(dateString).toLocaleDateString()
}

const formatTime = (timeString) => {
  return new Date(timeString).toLocaleString()
}

onMounted(() => {
  // 初始化数据
})
</script>

<style scoped>
.case-study {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  background: #f5f7fa;
  min-height: 100vh;
}

.page-header {
  text-align: center;
  margin-bottom: 30px;
}

.page-header h1 {
  color: #1e3c72;
  margin-bottom: 10px;
}

.case-categories {
  display: flex;
  gap: 10px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.category-btn {
  padding: 10px 20px;
  border: 2px solid #eee;
  background: white;
  border-radius: 25px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-btn:hover {
  border-color: #1e3c72;
  color: #1e3c72;
}

.category-btn.active {
  background: #1e3c72;
  color: white;
  border-color: #1e3c72;
}

.count {
  font-size: 12px;
  opacity: 0.7;
}

.case-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

.case-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: transform 0.2s ease;
}

.case-card:hover {
  transform: translateY(-2px);
}

.case-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.case-type {
  background: #17a2b8;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.case-difficulty {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.case-difficulty.beginner {
  background: #d4edda;
  color: #155724;
}

.case-difficulty.intermediate {
  background: #fff3cd;
  color: #856404;
}

.case-difficulty.advanced {
  background: #f8d7da;
  color: #721c24;
}

.case-content h3 {
  color: #1e3c72;
  margin-bottom: 10px;
}

.case-summary {
  color: #666;
  margin-bottom: 15px;
  line-height: 1.5;
}

.case-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 15px;
}

.tag {
  background: #f8f9fa;
  color: #666;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 11px;
}

.case-meta {
  display: flex;
  gap: 15px;
  margin-bottom: 15px;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #666;
  font-size: 12px;
}

.case-actions {
  display: flex;
  gap: 10px;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
}

.btn-primary {
  background: #1e3c72;
  color: white;
}

.btn-secondary {
  background: #6c757d;
  color: white;
}

.popular-cases {
  background: white;
  border-radius: 8px;
  padding: 30px;
  margin-bottom: 40px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.popular-cases h2 {
  color: #1e3c72;
  margin-bottom: 20px;
}

.popular-grid {
  display: grid;
  gap: 15px;
}

.popular-card {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px;
  border: 1px solid #eee;
  border-radius: 8px;
}

.popular-rank {
  width: 40px;
  height: 40px;
  background: #1e3c72;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.popular-content {
  flex: 1;
}

.popular-content h3 {
  color: #1e3c72;
  margin-bottom: 8px;
}

.popular-content p {
  color: #666;
  margin-bottom: 8px;
  font-size: 14px;
}

.popular-meta {
  display: flex;
  gap: 15px;
  font-size: 12px;
  color: #666;
}

.learning-progress {
  background: white;
  border-radius: 8px;
  padding: 30px;
  margin-bottom: 40px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.learning-progress h2 {
  color: #1e3c72;
  margin-bottom: 20px;
}

.progress-stats {
  display: flex;
  justify-content: space-around;
  margin-bottom: 30px;
  text-align: center;
}

.stat-item {
  padding: 20px;
}

.stat-number {
  font-size: 36px;
  font-weight: bold;
  color: #1e3c72;
  margin-bottom: 8px;
}

.stat-label {
  color: #666;
  font-size: 14px;
}

.progress-by-category {
  display: grid;
  gap: 15px;
}

.progress-item {
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 14px;
}

.progress-bar {
  height: 8px;
  background: #e9ecef;
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #28a745;
  transition: width 0.3s ease;
}

.recent-discussions {
  background: white;
  border-radius: 8px;
  padding: 30px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.recent-discussions h2 {
  color: #1e3c72;
  margin-bottom: 20px;
}

.discussion-list {
  display: grid;
  gap: 20px;
}

.discussion-item {
  display: flex;
  gap: 15px;
  padding: 15px;
  border: 1px solid #eee;
  border-radius: 8px;
}

.discussion-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
}

.discussion-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.discussion-content {
  flex: 1;
}

.discussion-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 14px;
}

.username {
  font-weight: bold;
  color: #1e3c72;
}

.case-title {
  color: #666;
}

.time {
  color: #999;
  font-size: 12px;
}

.discussion-text {
  color: #333;
  margin-bottom: 10px;
  line-height: 1.5;
}

.discussion-actions {
  display: flex;
  gap: 15px;
}

.action-btn {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.action-btn:hover {
  color: #1e3c72;
}

@media (max-width: 768px) {
  .case-categories {
    justify-content: center;
  }
  
  .case-list {
    grid-template-columns: 1fr;
  }
  
  .case-actions {
    flex-direction: column;
  }
  
  .popular-card {
    flex-direction: column;
    text-align: center;
  }
  
  .progress-stats {
    flex-direction: column;
    gap: 20px;
  }
  
  .discussion-item {
    flex-direction: column;
    text-align: center;
  }
}
</style> 